﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DoAnB
{
    public partial class frmThemBanAn : Form
    {
        public frmThemBanAn()
        {
            InitializeComponent();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (txtTenBan.Text == String.Empty)
                MessageBox.Show("Chưa nhập", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            else 
            {
                ketnoi kn = new ketnoi();
                string sql = "select * from Ban where TenBan='" + txtTenBan.Text + "'";
                if (kn.ExecuteReader(sql).HasRows)
                    MessageBox.Show("Tên bàn bị trùng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else
                {
                    sql = "Insert Into Ban(TenBan) Values(N'" + txtTenBan.Text + "')";
                    kn.ExeCuteNonQuery(sql);
                    MessageBox.Show("Thêm bàn thành công","Thông báo",MessageBoxButtons.OK,MessageBoxIcon.Information);
                    DialogResult = DialogResult.OK;
                    this.Close();
                }

            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
